package group

import (
	"context"
	"api/pb/group"
	"errors"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteMemberLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMemberLogic {
	return &DeleteMemberLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteMemberLogic) DeleteMember(req *types.DeleteMemberRequest) (resp *types.Empty, err error) {
	// 1. 参数校验
	if req.GroupID == 0 || req.UserID == 0 {
		return nil, errors.New("参数错误")
	}
	// 2. 移除成员
	_, err = l.svcCtx.GroupRPC.DeleteMember(l.ctx, &group.DeleteMemberRequest{GroupId: req.GroupID, UserId: req.UserID})
	if err != nil {
		return nil, err
	}
	return &types.Empty{}, nil
}
